var htmls = ""
var name = ""
$(document).ready(function () {
  (function () {
    var link = document.createElement('link')
    link.type = 'image/x-icon'
    link.rel = 'shortcut icon'
    link.href = '/favicon.ico'
    document.getElementsByTagName('head')[0].appendChild(link)
  }())
  gettags = function (e) {
    var evt = window.event || e
    if (evt.keyCode == 13) {
      var keyword = document.getElementById("tags").value
      window.location.href = "/search/search_page.html?keyword=" + keyword
    } else if (e == 0) {
      var keyword = document.getElementById("tags").value
      window.location.href = "/search/search_page.html?keyword=" + keyword
    }
  }
  counttags = function () {
    $.ajax({
      type: "GET",
      dataType: "jsonp",
      async: false,
      jsonpCallback: "loginCallback", //鑷畾涔夌殑jsonp鍥炶皟鍑芥暟鍚嶇О锛岄粯璁や负jQuery鑷姩鐢熸垚鐨勯殢鏈哄嚱鏁板悕
      url: "https://tianaw.95505.cn/tacpc/tiananapp/loginSession/getLoginSession",
      beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("content-type", "application/json; charset=utf-8")
      },
      success: function (data) {
        name = data
        check()
      },
      error: function (e) {
        name = ""
        check()
      }
    })
    var datas = {
      "url": ajaxUrl + "/claim_service/getnumtages",
      "params": ""
    }
    $.ajax({
      type: "POST",
      dataType: "json",
      url: baseUrl + "/api/forwarding",
      data: JSON.stringify(datas),
      beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("content-type", "application/json; charset=utf-8")
      },
      success: function (data) {
        if (data.state == 1) {
          //console.log(data.data)
          var html = ""
          if (data.data.length > 2) {
            html += "鐑棬鍏抽敭瀛楋細<a href='/search/search_page.html?keyword=" + data.data[0].tags + "'>" + data.data[0].tags + "</a><img class='line_img'src='/tianwebsite/pc/img/line_img.jpg'/><a href='/search/search_page.html?keyword=" + data.data[1].tags + "'>" + data.data[1].tags + "</a><img class='line_img' src='/tianwebsite/pc/img/line_img.jpg'/><a href='/search/search_page.html?keyword=" + data.data[2].tags + "'>" + data.data[2].tags + "</a><img class='line_img'src='/tianwebsite/pc/img/line_img.jpg'/><a href='/customer_service/electronic_policy.html'>淇濆崟楠岀湡</a>"
          } else if (data.data.length > 1) {
            html += "鐑棬鍏抽敭瀛楋細<a href='/search/search_page.html?keyword=" + data.data[0].tags + "'>" + data.data[0].tags + "</a><img class='line_img' src='/tianwebsite/pc/img/line_img.jpg'/><a href='/search/search_page.html?keyword=" + data.data[1].tags + "'>" + data.data[1].tags + "</a><img class='line_img'src='/tianwebsite/pc/img/line_img.jpg'/><a href='/customer_service/electronic_policy.html'>淇濆崟楠岀湡</a>"
          } else if (data.data.length > 0) {
            html += "鐑棬鍏抽敭瀛楋細<a href='/search/search_page.html?keyword=" + data.data[0].tags + "'>" + data.data[0].tags + "</a><img class='line_img'src='/tianwebsite/pc/img/line_img.jpg'/><a href='/customer_service/electronic_policy.html'>淇濆崟楠岀湡</a>"
          } else { }
          htmls = html
        } else { }
        check()
      }
    })
  }
  counttags()
  var timer = null

  function check () {
    var dom = document.getElementById("popular")
    if (dom) {
      //  鎵цdom鍔犺浇瀹屾垚鍚庣殑鎿嶄綔
      document.getElementById("popular").innerHTML = htmls
      if (!name) {
        var loginhtml = "<div class='login'>" +
          "<div class='center' id='login'>" +
          "<span>娆㈣繋鍏変复澶╁畨淇濋櫓鍟嗗煄</span>&nbsp;" +
          "<a target='_blank' href='https://tianaw.95505.cn/tacpc/#/login' id='login'>鐧诲綍</a><img class='line_img' src='/tianwebsite/pc/img/line_img.jpg'/>" +
          "<a target='_blank' href='https://tianaw.95505.cn/tacpc/#/register' id='register'>娉ㄥ唽</a>" +
          "</div>" +
          "</div>"
        $("#login").replaceWith(loginhtml)
      } else {
        var loginhtml = "<div class='login'>" +
          "<div class='center' id='login'>" +
          "<span>娆㈣繋鍏変复澶╁畨淇濋櫓鍟嗗煄</span>&nbsp;" +
          "<a target='_blank' href='https://tianaw.95505.cn/tacpc/#/mydata/myMes' id='login'>" + name + "</a><img class='line_img' src='/tianwebsite/pc/img/line_img.jpg'/>" +
          "<a target='_blank' href='https://tianaw.95505.cn/tacpc/#/mydata/myMes' id='login'>" + "涓汉涓績" + "</a><img class='line_img' src='/tianwebsite/pc/img/line_img.jpg'/>" +
          "<a target='_blank' href='https://tianaw.95505.cn/tacpc/tiananapp/loginSession/quit' id='register'>閫€鍑�</a>" +
          "</div>" +
          "</div>"
        $("#login").replaceWith(loginhtml)
      }
      $("#popular").html(htmls)
      //  娓呴櫎瀹氭椂鍣�
      //  娓呴櫎瀹氭椂鍣�
      if (!timer) {
        clearTimeout(timer)
      }
    } else {
      //鑷垜璋冪敤
      timer = setTimeout(check, 0)
    }
  }

  var x
  $("body").delegate(".funt_menu", "mouseenter", function () {
    var ids = $(this).attr("id")
    var y = ids.split("_")[1]
    x = $(".right_menu_tab").children("li")
    $(".choose_index" + y).addClass("backgroundorange")
    $(".right_content" + y).removeClass("displaynone")
    for (var i = 1; i < x.length + 1; i++) {
      if (i != y) {
        $(".choose_index" + i).removeClass("backgroundorange")
        $(".random_content" + i).addClass("displaynone")
      }
    }
  })
  $("body").delegate(".funt_menu", "mouseleave", function () {
    for (var i = 2; i < x.length + 2; i++) {
      $(".choose_index" + i).removeClass("backgroundorange")
      $(".right_content" + i).addClass("displaynone")
    }
  })
  $("body").delegate(".goToTop", "click", function () {
    $('html,body').animate({
      scrollTop: 0
    }, 'slow')
  })

  //璁块棶缁熻
  function getBrowserInfo () {
    var agent = navigator.userAgent.toLowerCase()
    var arr = []
    var system = agent.split(" ")[1].split(" ")[0].split("(")[1]
    arr.push(system)
    var regStr_edge = /edge\/[\d.]+/gi
    var regStr_ie = /trident\/[\d.]+/gi
    var regStr_ff = /firefox\/[\d.]+/gi
    var regStr_chrome = /chrome\/[\d.]+/gi
    var regStr_saf = /safari\/[\d.]+/gi
    var regStr_opera = /opr\/[\d.]+/gi
    var regStr_UC = /ubrowser\/[\d.]+/gi
    var regStr_BIDU = /bidubrowser\/[\d.]+/gi
    var regStr_360 = /360\/[\d.]+/gi
    if (agent.indexOf("bidubrowser") > 0) {
      arr.push("鐧惧害")
      return arr
    }
    if (agent.indexOf("ubrowser") > 0) {

      arr.push("UC")
      return arr
    }
    if (agent.indexOf("trident") > 0) {
      arr.push("IE")
      return arr
    };
    if (agent.indexOf("edge") > 0) {

      arr.push("Edge")
      return arr
    };
    if (agent.indexOf("firefox") > 0) {

      arr.push("鐏嫄")
      return arr
    }
    //Op
    if (agent.indexOf("opr") > 0) {

      arr.push("oprea")
      return arr
    }
    //Safari
    if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {

      arr.push("Safari")
      return arr
    }
    if (agent.indexOf("qqbrowser") > 0) {

      arr.push("QQ")
      return arr
    }
    //360
    if (agent.indexOf("chrome") > 0) {
      var is360 = _mime("type", "application/vnd.chromium.remoting-viewer")

      function _mime (option, value) {
        var mimeTypes = navigator.mimeTypes
        for (var mt in mimeTypes) {
          if (mimeTypes[mt][option] == value) {
            return true
          }
        }
        return false
      }
      if (is360) {
        // arr.push(agent.match(regStr_360)[0].split("/")[0]);
        arr.push("360")
        return arr
      }

    }
    //Chrome
    if (agent.indexOf("chrome") > 0) {
      arr.push(agent.match(regStr_chrome)[0].split("/")[0])
      arr.push(agent.match(regStr_chrome)[0].split("/")[1])
      return arr
    }

  };
  //ip鍦板潃鍜�
  function getIntnetIP () {
    var JSONP = document.createElement("script")
    JSONP.type = "text/javascript"
    JSONP.src = "https://pv.sohu.com/cityjson?ie=utf-8"
    document.getElementsByTagName("head")[0].appendChild(JSONP)
    myFunction()
  }

  function myFunction () {
    setTimeout(function () {
      var xmlhttp
      if (window.XMLHttpRequest) {
        //  IE7+, Firefox, Chrome, Opera, Safari 娴忚鍣ㄦ墽琛屼唬鐮�
        xmlhttp = new XMLHttpRequest()
      } else {
        // IE6, IE5 娴忚鍣ㄦ墽琛屼唬鐮�
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
      }
      xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { }
      }

      xmlhttp.open("post", baseUrl + "/api/forwarding", true)
      var data = {
        url: window.location.href,
        userAgent: navigator.userAgent,
        referrer: document.referrer,
        cookie: document.cookie,
        device: IsPC(),
        os: getBrowserInfo()[0],
        browser: getBrowserInfo()[1],
        ip: returnCitySN['cip'],
        area: returnCitySN['cname'],
      }
      var datas = {
        "url": ajaxUrl + "/cms/addvisitlob",
        "params": data
      }
      xmlhttp.setRequestHeader("content-type", "application/json")
      xmlhttp.send(JSON.stringify(datas))
    }, 1000)
  }
  //璁惧绫诲瀷
  function IsPC () {
    var device
    var system = {}
    var p = navigator.platform
    system.win = p.indexOf("Win") == 0
    system.mac = p.indexOf("Mac") == 0
    system.x11 = (p == "X11") || (p.indexOf("Linux") == 0)
    if (system.win || system.mac || system.xll) { //濡傛灉鏄數鑴戣烦杞埌
      device = "COMPUTER"
      return device
    } else { //濡傛灉鏄墜鏈�,璺宠浆鍒�
      device = "MOBILE"
      return device
    }
  };
  getIntnetIP()
});

(function (ji, a, x, i, n, j, s) {
  ji[n] = ji[n] || function () {
    (ji[n].n = ji[n].n || []).push(arguments)
  }
  v = new Date().getUTCDate()
  j = a.createElement(x), s = a.getElementsByTagName(x)[0]
  j.async = true
  j.charset = "UTF-8"
  j.src = i + "?v=" + v + "&id=bnd2cjh5m290ba&appName=ta838&appChannel=20008"
  s.parentNode.insertBefore(j, s)
})(window, document, "script", "//web.jiaxincloud.com/mcs.js", "_JIAXIN")
_JIAXIN()

function goPAGE () {
  if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
    if (window.location.href == 'https://www.95505.com.cn/customer_service/electronic_policy_download.html') {
      window.location.href = "/mobile/m_customer_service/m_download_elePolicy.html"
    } else if (window.location.href.indexOf('https://www.95505.com.cn/public_activity_content_atr')>-1) {
      var str = window.location.href.split('/');
      window.location.href = "/mobile/m_public_activity_content_atr/"+str[4]+"/index.html"
    }else{
      window.location.href = "/mobile"
    }
  }
}
goPAGE()